<template>
  <view class="message-item" :class="{ 'has-unread': message.unreadCount > 0 }">
    <view class="avatar-container">
      <sar-avatar size="45px" :src="message.icon" />
    </view>
    <view class="message-content">
      <view class="message-header">
        <text class="name">{{ message.name }}</text>
      </view>
      <view class="message-body">
        <text class="content">{{ message.content }}</text>
      </view>
    </view>
    <view class="badge-container">
      <sar-badge v-if="message.unreadCount > 0" :value="message.unreadCount" class="badge" />
    </view>
  </view>
</template>

<script lang="ts" setup>
import type { MessageItemData } from '../data'

defineProps<{
  message: MessageItemData
}>()
</script>

<style lang="scss" scoped>
.message-item {
  display: flex;
  padding: 15px 0;
  background-color: #fff;
  border-bottom: 1px solid #f0f0f0;
  position: relative;

  &.has-unread {
    .name {
      font-weight: bold;
    }

    .content {
      font-weight: 500;
    }
  }

  .avatar-container {
    position: relative;
    margin-right: 12px;
  }

  .badge-container {
    display: flex;
    align-items: center;
    padding: 0 10px;
  }

  .message-content {
    flex: 1;
    overflow: hidden;

    .message-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 5px;

      .name {
        font-size: 16px;
        color: #333;
      }

      .timestamp {
        font-size: 12px;
        color: #999;
      }
    }

    .message-body {
      .content {
        font-size: 14px;
        color: #666;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        line-height: 1.4;
      }
    }
  }
}
</style>
